import type { ArcoForm, ArcoFormRules } from '@/tool/ArcoFormTool.ts'
import { type Ref, ref, toRaw } from 'vue'


export class CommonFormService<T = Record<string, any>> {

    public readonly formRef = ref<ArcoForm | null>()

    public readonly formData: Ref<T> = ref({} as any)

    public readonly formRule: ArcoFormRules<T> = {}


    public constructor(formRef: Ref<ArcoForm | null>, formRule: ArcoFormRules<T> = {}) {
        this.formRef = formRef
        this.formRule = formRule

        this.onFormSubmit = this.onFormSubmit.bind(this)
    }


    public onFormSubmit(option: { errors: any, values: T }, submitEvent: SubmitEvent) {
        console.debug('表单提交', {
            errors: toRaw(option.errors),
            data: toRaw(option.values),
            submitEvent,
        })
    }

}
